package com.hjs.community.search.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.community.common.core.utils.Result;
import com.hjs.community.search.dto.PostDTO;
import com.hjs.community.search.service.SearchPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class SearchPostController {

    @Autowired
    private SearchPostService searchPostService;

    @GetMapping("/searchPostList")
    public Result searchPostList(String keyword) throws Exception {
        Result result = new Result();
        if (ObjectUtils.isEmpty(keyword)) {
            return result.error(400, "请输入关键字后在搜");
        }
        List<PostDTO> list = searchPostService.searchPostList(keyword);
        return result.ViewOk(list);
    }
}
